package com.elong.businesstravel.base.activity;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.dialog.CustomWaitDialog;
import com.android.support.jhf.dialog.CustomWaitDialog.OnKeyCancel;
import com.elong.businesstravel.ELongBusinessTravelApplication;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.mcrypt.MCrypt;
import com.umeng.analytics.MobclickAgent;
import com.umeng.message.PushAgent;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.StrictMode;

/**
 * activity基类
 * 
 * @author lenovo
 * 
 */
abstract public class BaseActivity extends Activity {

	protected Context mContext;

	protected ELongBusinessTravelApplication mApplication;

	private CustomWaitDialog mCustomWaitDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

//		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
//				.detectDiskReads().detectDiskWrites().detectNetwork()
//				.penaltyLog().build());
//		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
//				.detectLeakedSqlLiteObjects().penaltyLog().penaltyDeath()
//				.build());

		getWindow().setFormat(PixelFormat.RGBA_8888);

		mContext = this;

		mApplication = (ELongBusinessTravelApplication) mContext
				.getApplicationContext();
		// 友盟推送
		PushAgent.getInstance(mContext).onAppStart();
		
		DebugLog.setTag(mContext.getClass().getName());
	}

	protected void init() {

	}

	protected void setListener() {

	}

	protected void setTitleNavBar() {

	}

	/**
	 * 显示等待对话框
	 * 
	 * @param messageString
	 * @param onDismissListener
	 */
	public void showWaitDialog(String messageString,
			final OnKeyCancel onKeyCancel) {
		if (null == mCustomWaitDialog) {
			mCustomWaitDialog = new CustomWaitDialog(mContext,
					com.android.support.jhf.R.style.CustomWaitDialog);
			mCustomWaitDialog.setCancelable(true);
			mCustomWaitDialog.setCanceledOnTouchOutside(false);
			mCustomWaitDialog.setMessage(messageString);
			mCustomWaitDialog.setOnKeyCancelListener(new OnKeyCancel() {

				@Override
				public void onKeyCancelListener() {
					if (null != onKeyCancel) {
						onKeyCancel.onKeyCancelListener();
					}
					if (null != mCustomWaitDialog) {
						mCustomWaitDialog.cancel();
						mCustomWaitDialog = null;
					}
				}
			});
			mCustomWaitDialog.show();
		}
	}

	public void hideWaitDialog() {
		if (null != mCustomWaitDialog) {
			mCustomWaitDialog.cancel();
			mCustomWaitDialog = null;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

}
